import java.util.Arrays;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-29
 * Time: 21:02
 */
public class HashBuck2<K, V> {

    static class Node<K, V> {
        public K key;
        public V val;
        public Node<K, V> next;

        public Node(K key , V val) {
            this.key = key;
            this.val = val;

        }
    }

    public Node<K, V>[] arr = (Node<K, V>[]) new Node[10];
    public int usedSize;

    public static final double DEFAULT_LOAD_FACTOR = 0.75f;

    public void push(K key, V val) {
        int hashCode = key.hashCode();
        int index = hashCode % arr.length;

        Node<K, V> cur = arr[index];
        while (cur != null) {
            if(cur.key.equals(key)) {
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        Node<K, V> node = new Node<>(key, val);
        node.next = arr[index];
        arr[index] = node;
        usedSize++;
    }

    public V getVal(K key) {
        int hashCode = key.hashCode();
        int index = hashCode % arr.length;
        Node<K, V> cur = arr[index];
        while (cur != null) {
            if(cur.key.equals(key)) {
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }

}
